/*********************************************************************
 * Config.java created on Feb 2, 2010
 *
 * This file is part of Sure Tech Support Portal System. 
 * Copyright @ 2010 Sure Tech (HK) Limited. All rights reserved.
 * Sure Tech PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *********************************************************************/
package com.bizdigger.db.pool.util;

import java.net.Socket;

import org.apache.commons.pool.BaseKeyedPoolableObjectFactory;
import org.apache.commons.pool.KeyedObjectPool;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;

/**
 * @Author: Mac Wang
 * @Date: Feb 2, 2010 2:54:18 PM 
 * @Email: mac@suretech.com.hk
 */

public class Config {
	static {
        GenericKeyedObjectPool.Config cfg = new GenericKeyedObjectPool.Config();
        cfg.lifo = Boolean.valueOf(SystemParams.getProperty("lifo", "true"));
        cfg.maxActive = Integer.valueOf(SystemParams.getProperty("maxActive", "18"));
        cfg.maxIdle = Integer.valueOf(SystemParams.getProperty("maxIdle", "6"));
        cfg.maxWait = Integer.valueOf(SystemParams.getProperty("maxWait", "150000"));
        cfg.minEvictableIdleTimeMillis = Integer.valueOf(SystemParams.getProperty("minEvictableIdleTimeMillis", "100000"));
        cfg.minIdle = Integer.valueOf(SystemParams.getProperty("minIdle", "0"));
        cfg.numTestsPerEvictionRun = Integer.valueOf(SystemParams.getProperty("numTestsPerEvictionRun", "1"));
        cfg.lifo = Boolean.valueOf(SystemParams.getProperty("testOnBorrow", "false"));
        cfg.lifo = Boolean.valueOf(SystemParams.getProperty("testOnReturn", "false"));
        cfg.lifo = Boolean.valueOf(SystemParams.getProperty("testWhileIdle", "false"));
        cfg.timeBetweenEvictionRunsMillis = Integer.valueOf(SystemParams.getProperty("timeBetweenEvictionRunsMillis", "120000"));
        cfg.whenExhaustedAction = Byte.valueOf("whenExhaustedAction", 1);

        KeyedObjectPool pool = new GenericKeyedObjectPool(new BaseKeyedPoolableObjectFactory() 
        {
                @Override
                public Object makeObject(Object o) throws Exception {
                        if (o != null && o instanceof Socket)
                                return o;
                        else
                                return null;
                }
        }, cfg);
        
        try
        {
        	pool.close();
        }
        catch(Exception e)
        {
        	e.printStackTrace();
        }
	}
}
